package v1

import (
	"github.com/gin-gonic/gin"
	jsoniter "github.com/json-iterator/go"
	"wwt-gin-api/app/global/consts"
	"wwt-gin-api/app/global/request"
	"wwt-gin-api/app/service/seller_service"
	"wwt-gin-api/app/utils/cur_userinfo"
	"wwt-gin-api/app/utils/response"
)

type OrderController struct {
}

func (receiver *OrderController) Test(context *gin.Context) {
	userInfo := cur_userinfo.GetUserInfoByToken(context)
	response.Success(context, "ok", userInfo)
}

func (receiver *OrderController) OrdinaryPush(context *gin.Context) {
	goodsDataMap := context.GetStringMap(consts.ValidatorPrefix + "goodsData")
	goodsDataStr, _ := jsoniter.MarshalToString(goodsDataMap)
	goodsData := request.GoodsData{}
	_ = jsoniter.UnmarshalFromString(goodsDataStr, &goodsData)
	timingMap := context.GetStringMap(consts.ValidatorPrefix + "timing")
	timingStr, _ := jsoniter.MarshalToString(timingMap)
	timing := request.Timing{}
	_ = jsoniter.UnmarshalFromString(timingStr, &timing)
	expressServiceMap := context.GetStringMap(consts.ValidatorPrefix + "expressService")
	expressServiceStr, _ := jsoniter.MarshalToString(expressServiceMap)
	expressService := request.ExpressService{}
	_ = jsoniter.UnmarshalFromString(expressServiceStr, &expressService)
	taskRequireMap := context.GetStringMap(consts.ValidatorPrefix + "taskRequire")
	taskRequireStr, _ := jsoniter.MarshalToString(taskRequireMap)
	taskRequire := request.TaskRequire{}
	_ = jsoniter.UnmarshalFromString(taskRequireStr, &taskRequire)
	enterTheStoreWayMap := context.GetStringMap(consts.ValidatorPrefix + "enterTheStoreWay")
	enterTheStoreWayStr, _ := jsoniter.MarshalToString(enterTheStoreWayMap)
	enterTheStoreWay := request.EnterTheStoreWay{}
	_ = jsoniter.UnmarshalFromString(enterTheStoreWayStr, &enterTheStoreWay)
	placeOrderkeyWordWayObj, _ := context.Get(consts.ValidatorPrefix + "placeOrderkeyWordWay")
	placeOrderkeyWordWayByte, _ := jsoniter.Marshal(placeOrderkeyWordWayObj)
	placeOrderkeyWordWay := make([]request.PlaceOrderkeyWordWay, 0)
	_ = jsoniter.Unmarshal(placeOrderkeyWordWayByte, &placeOrderkeyWordWay)
	useAccretionFeeListObj, _ := context.Get(consts.ValidatorPrefix + "useAccretionFeeList")
	useAccretionFeeListByte, _ := jsoniter.Marshal(useAccretionFeeListObj)
	useAccretionFeeList := make([]string, 0)
	_ = jsoniter.Unmarshal(useAccretionFeeListByte, &useAccretionFeeList)
	res := seller_service.SellerServiceFactory().OrdinaryPush(context, &request.OrderReq{
		Platform:             context.GetString(consts.ValidatorPrefix + "platform"),
		Terminal:             context.GetString(consts.ValidatorPrefix + "terminal"),
		ShopId:               context.GetString(consts.ValidatorPrefix + "shopId"),
		GoodsCarryNum:        context.GetInt(consts.ValidatorPrefix + "goodsCarryNum"),
		Urls:                 context.GetString(consts.ValidatorPrefix + "urls"),
		GoodsData:            goodsData,
		Timing:               timing,
		TaskNum:              int(context.GetFloat64(consts.ValidatorPrefix + "taskNum")),
		OrderPlaceType:       context.GetString(consts.ValidatorPrefix + "orderPlaceType"),
		OrderPlaceEntry:      context.GetString(consts.ValidatorPrefix + "orderPlaceEntry"),
		OrderPlaceDelay:      context.GetString(consts.ValidatorPrefix + "orderPlaceDelay"),
		ExpressService:       expressService,
		TaskRequire:          taskRequire,
		EnterTheStoreWay:     enterTheStoreWay,
		PlaceOrderKeyWordWay: placeOrderkeyWordWay,
		RefundMethod:         context.GetString(consts.ValidatorPrefix + "refundMethod"),
		UseAccretionFeeList:  useAccretionFeeList,
		Body:                 context.GetString(consts.ValidatorPrefix + "body"),
	})
	response.ReturnJson(context, 200, res.Code, res.Message, "")
}
